<?php
include "db.php";
$msg_id = $_GET["id"] ?? 0;
if($msg_id<1){
  die("请传入有效ID");
}
$sql = "SELECT * FROM `liu` WHERE id = '{$msg_id}'";
$msg = $db->read($sql)[0];

$sql = "select * from reply join user on reply.user_id=user.id where msg_id = '{$msg_id}'  order by reply.id desc";
$rows = $db->read($sql);

?>
<!doctype html>
<html lang="zh-CN">

<head>

  <?php include("header.php") ?>
  <title>留言板 美化版</title>
</head>

<body>

  <div class="container">
    <?php include("menu.php") ?>
    <div class="col-12">
        <div class="border rounded p-2 mb-2">
          <div class="text-primary"><?php echo $msg["content"];?></div>
          <div><?php echo $msg["username"];?></div>
        </div>
      </div>
    <form action="reply_save.php" method="POST">
      <!-- 隐藏域 hidden-->
      <input type="hidden" name="msg_id" value="<?php echo $msg_id;?>">
      <div class="row">
        <div class="col-12">
          <div class="form-group">
            <textarea id="content" name="content" class="form-control" rows='4'></textarea>
            <script>
              var editor = new Simditor({
                textarea: $('#content')
                //optional options
              });
            </script>
          </div>
        </div>
        <div class="col-3">
        </div>
        <div class="col-9 d-flex">
          <div class="form-group ml-auto">
            <?php if ($user_id > 0): ?>
              <input class="btn btn-primary" type="submit" value="回复">
            <?php endif; ?>
          </div>
        </div>
      </div>
    </form>

    <div class="row">
      <div class="col-12">
         <?php foreach ($rows as $k) :?>
          <div class="border rounded p-2 mb-2">
            <div class="text-primary"><?php echo $k["content"]; ?></div>
            <div><?php echo $k["username"]; ?></div>
          </div>
          <?php endforeach; ?>
      </div>
    </div>
  </div>
</body>

</html>